#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int T,n;
int ans = -1;
int a[maxn];
int color[maxn];// red : 1  blue : 2
int c[maxn];

int getgs(int pos){
    for(int i = pos-1;i>=1;i--){
        if(color[i]==color[pos])
          if(a[i]==a[pos]) return a[i];
    }
    return 0;
}

void dfs(int s,int gs){
    if(s==n+1){
        //end conclusion
        if(gs>ans){
            for(int i = 1;i<=n;i++){
            }
            ans = gs;
        }
        return;
    }
    //make red
    color[s] = 1;
    dfs(s+1,gs+=getgs(s));

    //make blue
    color[s] = 2;
    dfs(s+1,gs+=getgs(s));


}

int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--){
        ans = -1;
        //memset(a,0,sizeof(a));
        //memset(color,0,sizeof(color));
        cin>>n;
        for(int i = 1;i<=n;i++) cin>>a[i];
        dfs(1,0);
        cout<<ans<<endl;
    }

    fclose(stdin);
    fclose(stdout);
    return 0;
}
